

class LcInterface
{
public:

	LcInterface();
	void input( int argc, char * const argv[]);

	LcClassifier*  getClassifier(){ return my_classifier;}

	bool IF_FEAT;
	//extract feature & label from filelist

	bool IF_TRAIN;
	//train classifier

	bool IF_TEST;
	//get response of a classifier for images in filelist

	bool IF_EXTRACT;
	
	string src_list;
	vector< string > src_name;
	string gt_list;
	vector< string > gt_name;

	string feat_list;
	vector< string > feat_name;

	string classifier_savename;

	string res_list;
	vector< string > res_name;	

	string feature_code_string;

	string classifier_name;

	void setClassifier();

	void init();

	LcClassifier* my_classifier;
};

void LcInterface::setClassifier()
{
	if(classifier_name == "rdt")
	{
		my_classifier = new LcRandomTrees;
	}
}

void scanList( string list , vector< string > & name )
{
	FILE * in = fopen( list.c_str() , "r");

	int n;

	fscanf( in , "%d" , &n );

	name.reserve( n );

	for(int i = 0; i < n ; i++)
	{
		char temp_str[800];
		fscanf( in , "%s", temp_str );
		name.push_back( string(temp_str) );
	}
	fclose( in );
}

LcInterface::LcInterface()
{
	IF_FEAT = false;
	IF_TRAIN = false;
	IF_TEST = false;
	IF_EXTRACT = true;

	classifier_name = "rdt";
	classifier_savename = "temp";
}

#include <ctime>

void LcInterface::init()
{
	srand(time(NULL));

	setClassifier();

	if(feature_code_string == "") feature_code_string = "l";


	if( IF_FEAT )
	{		
		scanList( src_list, src_name );
		scanList( gt_list, gt_name );
		scanList( feat_list, feat_name );
	}
	else
	{
		if( IF_EXTRACT )
		{
			scanList( src_list, src_name );
			scanList( gt_list, gt_name );
		}
		else
		{
			scanList( feat_list, feat_name );
			scanList( gt_list, gt_name );
		}

		if( IF_TRAIN )
		{
		}
		else if( IF_TEST )
		{
			scanList( res_list, res_name );
		}
	}
}

void LcInterface::input( int argc, char * const argv[])
{
	for(int ind = 1;ind < argc;ind++)
	{
		/*** Parse switches ***/
		if (argv[ind][0] == '-') {
			switch (argv[ind][1]) {
				case 'a':
					IF_FEAT = true;
					break;
				case 'b':
					IF_TRAIN = true;
					break;
				case 'c':
					IF_TEST = true;
					break;
				case 'd':
					IF_EXTRACT = false;
					break;
				case 's':
					src_list = string(argv[++ind]);
					break;
				case 'g':
					gt_list = string(argv[++ind]);
					break;
				case 'f':
					feat_list = string(argv[++ind]);
					break;
				case 'r':
					res_list = string(argv[++ind]);
					break;
				case 'm':
					classifier_savename = string(argv[++ind]);
					break;
				case 'v':
					feature_code_string =  string(argv[++ind]);
					break;
				default : printf("Unknown switch '%c'\n", argv[ind][1]);
				break;
			}//end case
		}//end if
	}//end for

	init();
}